package imageServer.web;

import imageServer.config.ImageConfigVo;
import imageServer.vo.ImageUploadResponseVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Created by xiaoqian on 2016/8/31.
 */
@Controller
@RequestMapping(ImageConfigVo.API_PATH)
public class FileUploadController extends AbstractUploadAct {

    private static final Logger logger = LoggerFactory.getLogger(FileUploadController.class);

    @RequestMapping(method = RequestMethod.POST)
    @ResponseBody
    public Object upload(HttpServletRequest request, HttpServletResponse response) throws IOException {
        MultipartHttpServletRequest mrequest = ((MultipartHttpServletRequest)request);
 response.setHeader("Access-Control-Allow-Origin", "*");
        List<ImageUploadResponseVo> responseVos =  uploadFiles(request,  mrequest);

        return responseVos;
    }

}
